ans=[]
for _ in range(int(input())):
n=int(input())
k=0
x=[]
for i in range(n):
s=list(map(int, input().split()))
x.append(s)
for i in range(n):
for j in range(n):
if (i+j)%4==0 and i+j<n and j%2==0:
k=k^x[i][j]
if (i+j)%4==0 and i+j>=n and j%2!=0:
k=k^x[i][j]
if (n-1-i+j)%4==0 and (n-1-i+j)<n and j%2==0:
k=k^x[i][j]
if (n-1-i+j)%4==0 and (n-1-i+j)>=n and j%2!=0:
k=k^x[i][j]
ans.append(k)
print('\n'.join([str(i) for i in ans]))
1710C - XOR Triangle | 415C - Mashmokh and Numbers |
8A - Train and Peter | 591A - Wizards' Duel |
1703G - Good Key Bad Key | 1705A - Mark the Photographer |
1707A - Doremy's IQ | 1706B - Making Towers |
1325B - CopyCopyCopyCopyCopy | 1649C - Weird Sum |
1324B - Yet Another Palindrome Problem | 525A - Vitaliy and Pie |
879A - Borya's Diagnosis | 1672B - I love AAAB |
1673A - Subtle Substring Subtraction | 1345A - Puzzle Pieces |
711A - Bus to Udayland | 779B - Weird Rounding |
1703D - Double Strings | 1704C - Virus |
63A - Sinking Ship | 1704B - Luke is a Foodie |
298B - Sail | 239A - Two Bags of Potatoes |
1704E - Count Seconds | 682A - Alyona and Numbers |
44A - Indian Summer | 1133C - Balanced Team |
1704A - Two 0-1 Sequences | 1467A - Wizard of Orz |